package com.holly.unit.deform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.holly.unit.deform.entity.DesignFormData;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * 接口描述: 表单设计数据仓库类
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/4/6 9:53
 */
public interface DeformDataMapper extends BaseMapper<DesignFormData> {

    /**
     * 通过主表ID删除数据
     *
     * @param mainId
     * @return
     */
    public boolean deleteByMainId(@Param("mainId") String mainId);

    /**
     * 通过主表ID查询数据
     *
     * @param mainId
     * @return
     */
    public List<DesignFormData> selectByMainId(@Param("mainId") String mainId);

    /**
     * 查询一张表的一条记录
     * 该查询是查询所有字段即select * from {table} where id = {onlineDataId}
     * @param tbname 表名
     * @param onlineDataId 数据id
     * @return
     */
    public Map<String,Object> queryOneByTableNameAndId(@Param("tbname")String tbname, @Param("onlineDataId")String onlineDataId);

    /**
     * 通过表名获取子表配置
     * @param table_name
     * @return
     */
    public String getSubTablesByTableName(String table_name);

    @Select("select * from ${tableName} where id = #{tableId}")
    Map<String,Object> getFormData(@Param("tableId") String tableId, @Param("tableName") String tableName);

    @Insert("${sql}")
    int insertFormData(@Param("sql") String sql);

    @Update("${sql}")
    int updateFormData(@Param("sql") String sql);

    @Delete("delete from ${tableName} where id = #{tableId}")
    int deleteFormData(@Param("tableId") String tableId, @Param("tableName") String tableName);


    List<Map<String, Object>> queryFormDataList(@Param("page") Page<Map<String, Object>> page,@Param("tableName") String tableName, @Param("query") String query);

    void deleteBatchForm(@Param("ids")List<String> asList,@Param("tableName") String tableName);


    IPage<Map> getTableDataByColumn(@Param("page") Page<Map> page,@Param("tableName") String tableName, @Param("columnList") List<String> columnList);


}
